package com.fly.dto;

import com.fasterxml.jackson.annotation.JsonView;
import com.fly.validator.MyConstraint;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.constraints.Past;
import java.util.Date;

public class User {
    public interface UserSimpleView{}; //用户简单视图,不显示密码字段
    public interface UserDetailView extends UserSimpleView{}; //用户详细视图,显示密码

    private String id;
    @MyConstraint(message = "测试校验注解")
    private String username;

    @NotBlank(message = "密码不能为空")
    private String password;
    @Past(message = "生日为过去的时间") // 必须是过去的时间
    private Date birthday;

    public User() {
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User(String id, String username, String password) {
        this.id = id;
        this.username = username;
        this.password = password;
    }

    @JsonView(UserSimpleView.class)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @JsonView(UserDetailView.class)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @JsonView(UserSimpleView.class)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @JsonView(UserSimpleView.class)
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
